package com.example.wanghao.wangyixinwen.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by wanghao on 2016/5/16.
 */
public class SharedPreferenceTools {

    private static final String SP_NAME = "config";
    private static SharedPreferences sp;

    //保存字符串
    public static void saveString(Context context, String key, String value){
       if (sp == null) {
           sp = context.getSharedPreferences(SP_NAME, Context.MODE_APPEND);

       }
        sp.edit().putString(key, value).commit();
    }
    //获取字符串
    public static String getString(Context context, String key, String defValue){
        if (sp == null){
            sp = context.getSharedPreferences(SP_NAME,Context.MODE_APPEND);
        }
        String result = sp.getString(key, defValue);
        return result;
    }
    //保存布尔值
    public static void saveBoolean(Context context, String key, boolean value){
       if (sp == null) {
           sp = context.getSharedPreferences(SP_NAME, Context.MODE_APPEND);

       }
        sp.edit().putBoolean(key, value).commit();
    }
    //获取布尔值
    public static boolean getBoolean(Context context, String key, boolean defValue){
        if (sp == null){
            sp = context.getSharedPreferences(SP_NAME,Context.MODE_APPEND);
        }
        boolean result = sp.getBoolean(key, defValue);
        return result;

    }
}
